package com.itheima.tanhua.server.controller;

import com.itheima.tanhua.domain.UserInfo;
import com.itheima.tanhua.po.*;
import com.itheima.tanhua.server.service.UserService;
import com.itheima.tanhua.vo.LoginVo;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.Path;

/**
 * @author itheima
 * @since 2022-01-13
 */
@RestController
@RequestMapping("users")
public class UsersController {

    @Autowired
    private UserService userService;

    /**
     * Day02 查询用户
     *
     * @return ResponseEntity
     */
    @GetMapping
    public ResponseEntity getUserInfo() {
        UserInfo myUserInfo = userService.getMyUserInfo();
        return ResponseEntity.ok(myUserInfo);
    }

    /**
     * Day02 更新用户信息
     *
     * @param userInfo userInfo
     * @return ResponseEntity
     */
    @PutMapping
    public ResponseEntity updateUserInfo(@RequestBody UserInfo userInfo) {
        Boolean result = userService.updateUserInfo(userInfo);
        return ResponseEntity.status(result ? HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * Day03 通知设置
     *
     * @return ResponseEntity
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity updateNotificationsSetting(@RequestBody NotificationsPo notificationsPo) {
        Boolean result = userService.updateNotifications(notificationsPo);
        return ResponseEntity.status(result ? HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * Day03 查询通用设置
     *
     * @return ResponseEntity
     */
    @GetMapping("/settings")
    public ResponseEntity getSettings() {
        return ResponseEntity.ok(userService.getSettings());
    }

    /**
     * Day03 设置陌生人问题
     *
     * @param questionsPo 陌生人问题
     * @return ResponseEntity
     */
    @PostMapping("/questions")
    public ResponseEntity updateQuestions(@RequestBody QuestionsPo questionsPo) {
        Boolean result = userService.updateQuestion(questionsPo.getContent());
        return ResponseEntity.status(result ? HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }


    /**
     * Day03 移除陌生人问题
     *
     * @param uid uid
     * @return ResponseEntity
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable String uid) {
        return ResponseEntity.ok(null);
    }

    /**
     * Day03 获取陌生人问题列表
     *
     * @param page     页码
     * @param pageSize 每页显示条数
     * @return ResponseEntity
     */
    @GetMapping("/blacklist")
    public ResponseEntity getBlackList(Integer page, Integer pageSize) {
        return ResponseEntity.ok(null);
    }
}
